package io.vertx.kue

import io.vertx.kue.queue.Job
import io.vertx.kue.service.JobService
import io.vertx.codegen.annotations.Fluent
import io.vertx.codegen.annotations.VertxGen
import io.vertx.core.AsyncResult
import io.vertx.core.Handler
import io.vertx.core.Vertx
import io.vertx.core.eventbus.Message
import io.vertx.core.json.JsonObject


/**
 * A callback-based [io.vertx.blueprint.kue.Kue] interface for Vert.x Codegen to support polyglot languages.
 *
 * @author Eric Zhao
 */
@VertxGen
interface CallbackKue : JobService {

    fun createJob(type: String, data: JsonObject): Job

    @Fluent
    fun <R> on(eventType: String, handler: Handler<Message<R>>): CallbackKue

    @Fluent
    fun saveJob(job: Job, handler: Handler<AsyncResult<Job>>): CallbackKue

    @Fluent
    fun jobProgress(job: Job, complete: Int, total: Int, handler: Handler<AsyncResult<Job>>): CallbackKue

    @Fluent
    fun jobDone(job: Job): CallbackKue

    @Fluent
    fun jobDoneFail(job: Job, ex: Throwable): CallbackKue

    @Fluent
    fun process(type: String, n: Int, handler: Handler<Job>): CallbackKue

    @Fluent
    fun processBlocking(type: String, n: Int, handler: Handler<Job>): CallbackKue

    companion object {

        fun createKue(vertx: Vertx, config: JsonObject): CallbackKue {
            return CallbackKueImpl(vertx, config)
        }
    }
}
